import java.util.*;
public class Solution {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> hash = new HashMap<>();
        for(int i=0;i<nums.length;i++){
            if(hash.containsKey(target-nums[i])){
                return new int[]{hash.get(target-nums[i]),i};
            }else{
                hash.put(nums[i],i);
            }
        }
        return new int[]{-1,-1};
    }
    public static void main(String[] args) {
        Solution solution = new Solution();
        int count = 0;
        int total = 2;
        int[] nums_1 = {2, 7, 11, 15};
        int target_1 = 9;
        String anticipate_1 = "[0, 1]";
        String actual_1 = Arrays.toString(solution.twoSum(nums_1, target_1));
        if (!anticipate_1.equals(actual_1)) {
            System.out.println("案例未通过:");
            System.out.println("nums = {2,7,11,15};target = 9;");
            System.out.println("实际输出:" + actual_1);
            System.out.println("预期输出:" + anticipate_1);
            count++;
        }
        int[] nums_2 = {3, 2, 4};
        int target_2 = 6;
        String actual_2 = Arrays.toString(solution.twoSum(nums_2, target_2));
        String anticipate_2 = "[1, 2]";
        if (!anticipate_2.equals(actual_2)) {
            System.out.println("未通过案例:");
            System.out.println("nums = [3, 2, 4];\n" +
                    "target = 9;");
            System.out.println("实际输出:" + actual_2);
            System.out.println("预期输出:" + anticipate_2);
            count++;
        }
        System.out.println((total - count) + "/" + total + "个测试用例通过.");
    }
}